﻿<UserControl x:Class="EzDesk.DesktopClient.View.FeedView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:converter="clr-namespace:EzDesk.Generic.WPF.Converter;assembly=EzDesk.Generic.WPF" xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase" mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <Style x:Key="ListBoxItemStyle" TargetType="{x:Type ListBoxItem}">
            <Setter Property="HorizontalContentAlignment"  Value="Stretch"/>
            <Setter Property="Padding" Value="0,0,0,1"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListBoxItem}">
                        <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
                            <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <ControlTemplate x:Key="FeedListBoxControlTemplate" TargetType="{x:Type ListBox}">
            <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="1" SnapsToDevicePixels="True">
                <ScrollViewer Focusable="False" Padding="{TemplateBinding Padding}">
                    <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                </ScrollViewer>
            </Border>
            <ControlTemplate.Triggers>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
                </Trigger>
                <Trigger Property="IsGrouping" Value="True">
                    <Setter Property="ScrollViewer.CanContentScroll" Value="False"/>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
        <DataTemplate x:Key="FeedListBoxItemDataTemplate">
            <Grid Height="Auto" Width="{Binding ActualWidth, ElementName=updateList}">
                <ContentControl Content="{Binding View}" d:LayoutOverrides="Height" Margin="0,0,2,0" />
            </Grid>
        </DataTemplate>
        <CollectionViewSource Source="{Binding UpdateFeeds}" x:Key="UpdateCollectionView">
        </CollectionViewSource>
        <CollectionViewSource Source="{Binding NotificationFeeds}" x:Key="NotificationCollectionView">
        </CollectionViewSource>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
        </Grid.RowDefinitions>
        <ScrollViewer  x:Name="FeedScrollViewer" HorizontalContentAlignment="Stretch" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" Margin="0,2">
            <ScrollViewer.Background>
                <ImageBrush  Viewport="0,0,0.5,0.1" Opacity="0.3" Stretch="Uniform" TileMode="Tile" ImageSource="{StaticResource FeedViewBackground}"/>
            </ScrollViewer.Background>
            <StackPanel Orientation="Vertical">
                <ListBox x:Name="notificationList" 
                         ItemsSource="{Binding Source={StaticResource NotificationCollectionView}}"
					VirtualizingStackPanel.VirtualizationMode="Recycling" 
					Mouse.PreviewMouseWheel="listboxFeedList_PreviewMouseWheel" 
					Background="{x:Null}" BorderBrush="{x:Null}" 
                    ItemContainerStyle="{DynamicResource ListBoxItemStyle}" 
					Margin="0" d:LayoutOverrides="Width" 
					Template="{DynamicResource FeedListBoxControlTemplate}" 
					ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
					ScrollViewer.VerticalScrollBarVisibility="Disabled" 
					ItemTemplate="{DynamicResource FeedListBoxItemDataTemplate}" />
                <ListBox x:Name="updateList" ItemsSource="{Binding Source={StaticResource UpdateCollectionView}}" 
					VirtualizingStackPanel.VirtualizationMode="Recycling" 
					Mouse.PreviewMouseWheel="listboxFeedList_PreviewMouseWheel" 
					Background="{x:Null}" BorderBrush="{x:Null}" 
					ItemContainerStyle="{DynamicResource ListBoxItemStyle}" 
					Margin="0" d:LayoutOverrides="Width" 
					ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
					ScrollViewer.VerticalScrollBarVisibility="Disabled" 
                    RequestBringIntoView="updateList_RequestBringIntoView"
					ItemTemplate="{DynamicResource FeedListBoxItemDataTemplate}" />
            </StackPanel>
        </ScrollViewer>

        <StackPanel HorizontalAlignment="Center" Margin="0,-80,0,0"  Visibility="{Binding NoFeed,Converter={StaticResource BooleanToHiddenVisibilityConverter}}" VerticalAlignment="Center">
            <Image Width="100" Source="{StaticResource FullLogoGreen}"></Image>
            <TextBlock Margin="30,3" Foreground="White" FontSize="14" TextWrapping="WrapWithOverflow" FontWeight="Bold" Text="{StaticResource BlankBackgroundMessage}"></TextBlock>
        </StackPanel>

        <Grid VerticalAlignment="Bottom" Margin="0,1,0,0" Grid.Row="1"  Background="{StaticResource BackGray}">
            <TextBlock  FontWeight="Bold" HorizontalAlignment="Left" VerticalAlignment="Bottom" d:LayoutOverrides="Height" Margin="20,3,0,0" Foreground="White">
                <Run  Text="{StaticResource PreHandle}"/>
                 <Run Text="{Binding ToHandleCount,Mode=OneWay}">
                 </Run> <Run  Text="条"></Run>
            </TextBlock>
            <Grid HorizontalAlignment="Right"  VerticalAlignment="Bottom" Width="117" d:LayoutOverrides="Height" Margin="0,0,5,0">
                <Button Content="{DynamicResource MarkAllRead}" Command="{Binding MarkAllReadCommand}" Height="16" VerticalAlignment="Center" HorizontalAlignment="Left" Width="56" Style="{DynamicResource BorderedButtonStyle}" Foreground="White" BorderBrush="#FF999999" Background="{DynamicResource DarkBackGray}" BorderThickness="1"/>
                <Button Content="{DynamicResource ClearAll}" Height="16" VerticalAlignment="Center" HorizontalAlignment="Right" Width="56" Background="{DynamicResource DarkBackGray}" Foreground="White" BorderBrush="#FF999999" Style="{DynamicResource BorderedButtonStyle}" BorderThickness="1"/>
            </Grid>
        </Grid>
    </Grid>
</UserControl>
